package com.rtst.widget.listview;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class AbstractBuilder {
	protected ViewGroup mParentView;
	protected LayoutInflater mLayoutInflater;
	protected volatile List<Object> mData;
	
	protected abstract void buildLayout(ViewGroup parent);

	// Constructor
	public AbstractBuilder(Context context, ViewGroup parent) {
		mParentView = parent;
		mLayoutInflater = LayoutInflater.from(context);
		mData = new ArrayList<Object>();
	}

	// Internal build product
	
	protected abstract void buildData();
	
	public abstract void build();

	public abstract void refresh();
	
	public abstract View buildViewHolder();

	public abstract List<View> buildViewHolderContent(View base);

	public abstract void buildViewHolderContentData(int position,
			List<View> views, List<Object> data);

	public List<Object> getData() {
		return mData;
	}
	
	public void setData(List<Object> data) {
		synchronized (mData) {
			mData.clear();
			if(data != null) {
				mData = data;
			}
		}
	}
	
	public void clear() {
		synchronized (mData) {
			mData.clear();
		}
	}
}
